package com.asiainfo.lop;

import android.app.Activity;
import android.view.KeyEvent;
import android.widget.Toast;

/**
 * Created by wucm(wucm@asiainfo.com) on 2016/5/28 17:04.
 */
public class BaseMainActivity extends Activity {
    String flag;
    String reason;
    Object data;

    private long firstTime = 0;
    private int clickNum = 0;

    /**
     * 点击两次退出
     */
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_BACK:
                long secondTime = System.currentTimeMillis();
                clickNum++;
                if (secondTime - firstTime > 2000) {
                    if (clickNum > 1) {
                        Toast.makeText(this, "再按一次退出程序", Toast.LENGTH_SHORT).show();
                    }
                    firstTime = secondTime;//更新firstTime
                    return true;
                } else {
                    System.exit(0);
                }
                break;
        }
        return super.onKeyUp(keyCode, event);
    }
}
